package com.xmkj.carwash.utils;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.ImageViewTarget;

import cn.finalteam.galleryfinal.widget.GFImageView;

/**
 * 作者：LMZ on 2016/8/26 0026 11:37
 */
public class GlideImageLoader implements cn.finalteam.galleryfinal.ImageLoader {
    @Override
    public void displayImage(Activity activity, String path, final GFImageView imageView, Drawable defaultDrawable, int width, int height) {

        RequestBuilder<Drawable> requestBuilder = Glide.with(activity)
                .load("file://" + path);


        RequestOptions options = new RequestOptions()
                .centerCrop()
                .placeholder(defaultDrawable)
                .error(defaultDrawable)
                .priority(Priority.HIGH)
                .diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true);

        Glide.with(activity)
                .load("file://" + path)
                .apply(options)
                .thumbnail(Glide.with(activity)
                        .load("file://" + path))
                .into(new ImageViewTarget<Drawable>(imageView) {
                    @Override
                    protected void setResource(@Nullable Drawable resource) {
                        imageView.setImageDrawable(resource);
                    }
                });

//        Glide.with(activity)
//                .load("file://" + path)
//
//                .override(width, height)
//                .diskCacheStrategy(DiskCacheStrategy.NONE) //不缓存到SD卡
//                .skipMemoryCache(true)
//                //.centerCrop()
//                .into(new ImageViewTarget<GlideDrawable>(imageView) {
//                    @Override
//                    protected void setResource(GlideDrawable resource) {
//                        imageView.setImageDrawable(resource);
//                    }
//
//                    @Override
//                    public void setRequest(Request request) {
//                        imageView.setTag(R.id.adapter_item_tag_key,request);
//                    }
//
//                    @Override
//                    public Request getRequest() {
//                        return (Request) imageView.getTag(R.id.adapter_item_tag_key);
//                    }
//                });
    }

    @Override
    public void clearMemoryCache() {
    }
}
